<%-- 
    Document   : admvendedor
    Created on : 08/15/2013, 09:30:18 PM
    Author     : grakeskull
--%>

<%@page import="java.util.Date"%>
<%@page import="edu.capex.farmacus.encapsulates.VendedorfarmaciamedicamentoPK"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="edu.capex.farmacus.encapsulates.Autenticacion"%>
<%@page import="edu.capex.farmacus.Manager.VendedorFarmaciaMedicamentoManager"%>
<%@page import="edu.capex.farmacus.encapsulates.Vendedorfarmaciamedicamento"%>
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<%
    SimpleDateFormat yyyyMMdd = new SimpleDateFormat("yyyy/MM/dd");

    if (request.getParameter("vendedor") != null && request.getParameter("medicamento") != null && request.getParameter("farmacia") != null
            && request.getParameter("observacion") != null && request.getParameter("montoMedicina") != null && request.getParameter("venta") != null
            && request.getParameter("fechaDelPK") != null) {
        Vendedorfarmaciamedicamento vendedorAModificar = new VendedorFarmaciaMedicamentoManager().findVendedorfarmaciamedicamento(new VendedorfarmaciamedicamentoPK(
                new Integer(request.getParameter("vendedor")),
                new Integer(request.getParameter("farmacia")),
                new Integer(request.getParameter("medicamento")),
                yyyyMMdd.parse(request.getParameter("fechaDelPK"))));
        
        new VendedorFarmaciaMedicamentoManager().destroy(vendedorAModificar.getVendedorfarmaciamedicamentoPK());
        vendedorAModificar.getVendedorfarmaciamedicamentoPK().setFechaVenta(yyyyMMdd.parse(request.getParameter("fechaVenta")));
        vendedorAModificar.setObservacion(request.getParameter("observacion"));
        vendedorAModificar.setCobro(new Integer(vendedorAModificar.getMedicamentos().getCostoMedicamento()) * new Integer(request.getParameter("montoMedicina").trim()));
        vendedorAModificar.setVenta(new Integer(request.getParameter("venta").trim()));

        new VendedorFarmaciaMedicamentoManager().create(vendedorAModificar);
    }

%>
<html>
    <head>
        <%@include file="/resources/header.jsp" %>
        <script src="../js/bsa.js"></script>
    </head>

    <body class="preview" data-spy="scroll" data-target=".subnav" data-offset="80">

        <%@include file="/resources/header1.jsp" %>



        <div class="container">

            <section id="typography">
                <h2>Bienvenido <%=((Autenticacion) request.getSession().getAttribute("usuarioLogeado")).getIdVendedor().getNombre()%></h2>
                <%@include file="menuvendedor.jsp" %>
                <h2>Labores Asignadas</h2>


                <section id="tables">

                    <table class="table table-bordered table-striped table-hover" id="myTable">
                        <thead>
                            <tr>
                                <th>Fecha</th>
                                <th>Vendedor</th>
                                <th>Farmacia</th>
                                <th>Medicamento</th>
                                <th>Observacion</th>
                                <th filter="false">Venta</th>
                                <th filter="false">Cantidad Medicamento</th>
                                <th filter="false">Fecha De Venta</th>
                                <th>Observacion Vendedor</th>
                                <th filter="false">Guardar</th>
                            </tr>
                        </thead>

                        <tbody>
                            <%
                                for (Vendedorfarmaciamedicamento temp : new VendedorFarmaciaMedicamentoManager().findEntitiesVendedoresFarmaciaMedicamentoFilteredByVendedor(((Autenticacion) request.getSession().getAttribute("usuarioLogeado")).getIdVendedor().getId())) {
                            %>
                            <tr>
                                <td><%=yyyyMMdd.format(temp.getVendedorfarmaciamedicamentoPK().getFechaVenta())%></td>
                                <td><%=temp.getVendedores().getNombre()%></td>
                                <td><%=temp.getFarmacias().getNombre()%></td>
                                <td><%=temp.getMedicamentos().getNombreMedicamento()%></td>
                                <td><%=temp.getObservacion()%></td>

                        <form method="POST" action="#" class="needValidation">
                            <td> 
                                <div class="control-group">
                                    <label class="control-label" for="optionsCheckbox"></label>
                                    <div class="controls">
                                        <label class="checkbox">
                                            <input type="hidden" id="optionsCheckbox" value="<%=temp.getVendedores().getId()%>" name="vendedor">
                                            <input type="hidden" id="optionsCheckbox" value="<%=temp.getFarmacias().getId()%>" name="farmacia">
                                            <input type="hidden" id="optionsCheckbox" value="<%=temp.getMedicamentos().getIdmedicamentos()%>" name="medicamento">
                                            <input type="hidden" id="optionsCheckbox" value="<%=yyyyMMdd.format(temp.getVendedorfarmaciamedicamentoPK().getFechaVenta())%>" name="fechaDelPK">
                                            <%if (temp.getVenta() > 0) {%>
                                            <input type="text" id="optionsCheckbox" name="venta" data-required readonly>
                                            <%} else {%>
                                            <input type="text" id="optionsCheckbox" name="venta" data-required>
                                            <%}%>
                                        </label>
                                    </div>
                                </div> 
                            </td>
                            <td> 
                                <div class="control-group">
                                    <label class="control-label" for="optionsCheckbox"></label>
                                    <div class="controls">
                                        <label class="checkbox">
                                            <%if (temp.getVenta() > 0) {%>
                                            <input type="text" id="optionsCheckbox" name="montoMedicina" data-required readonly>
                                            <%} else {%>
                                            <input type="text" id="optionsCheckbox" name="montoMedicina" data-required>
                                            <%}%>
                                        </label>
                                    </div>
                                </div> 
                            </td>
                            <td> 
                                <div class="control-group">
                                    <label class="control-label" for="optionsCheckbox"></label>
                                    <div class="controls">
                                        <%if (temp.getVenta() > 0) {%>
                                        <input type="text"  name="fechaVenta" value="<%=yyyyMMdd.format(temp.getVendedorfarmaciamedicamentoPK().getFechaVenta())%>" class="" readonly data-required>
                                        <%} else {%>
                                        <input type="text"  name="fechaVenta" value="<%=yyyyMMdd.format(new Date())%>" class="datePicker" data-required>
                                        <%}%>
                                    </div>
                                </div> 
                            </td>
                            <td>
                                <div class="control-group">
                                    <div class="controls">
                                        <%if (temp.getVenta() > 0) {%>
                                        <textarea class="input-xlarge" id="textarea" rows="3" name="observacion" data-required disabled></textarea>
                                        <%} else {%>
                                        <textarea class="input-xlarge" id="textarea" rows="3" name="observacion" data-required></textarea>
                                        <%}%>
                                    </div>
                                </div>
                            </td>
                            <td>
                                <div class="control-group">
                                    <%if (temp.getVenta() > 0) {%>
                                    <input type="submit" id="optionsCheckbox" value="Guardar" name="guardar" disabled/>
                                    <%} else {%>
                                    <input type="submit" id="optionsCheckbox" value="Guardar" name="guardar"/>
                                    <%}%>
                                </div>
                            </td>
                        </form>

                        </tr>
                        <%}%>
                        </tbody>
                    </table>
                </section>


                <%@include file="/resources/footer1.jsp" %>
                <script type="text/javascript">
                    $(document).ready(function() {
                        $('#myTable').tableFilter();
                        $('.needValidation').validate({
                            onKeyup: true,
                            eachValidField: function() {

                                $(this).closest('div').removeClass('error').addClass('success');
                            },
                            eachInvalidField: function() {

                                $(this).closest('div').removeClass('success').addClass('error');
                            }
                        });
                        $('.datePicker').datepicker(
                                {
                                    "dateFormat": "yy/mm/dd"
                                }
                        );
                    });
                </script>
            </section>
        </div>
    </body>
</html>

